package com.lzh.exer;

public class StudentTest1 {
	
	public static void main(String[] args) {
	
		Students[] stus = new Students[20];
		
		for(int i=0;i<stus.length;i++) {
			stus[i] = new Students();
			stus[i].number = i+1;
			stus[i].state = (int)(Math.random()*(6-1+1)+1);
			stus[i].score = (int)(Math.random()*(100-0+1));
		}
		
		StudentTest1 st = new StudentTest1();
		st.print(stus);
		System.out.println("**********************");
		st.stateThree(stus, 3);
		System.out.println("**********************");
		st.sort(stus);
		st.print(stus);
	}
	public void print(Students[] stus) {
		for(int i=0;i<stus.length;i++) {
			stus[i].info();
		}
	}
	public void stateThree(Students[] stus,int state) {
		for(int i=0;i<stus.length;i++) {
			if(stus[i].state == state) {
				stus[i].info();
			}
		}
	}
	public void sort(Students[] stus) {
		for(int i=0;i<stus.length-1;i++) {
			for(int j=0;j<stus.length-i-1;j++) {
				if(stus[j].score > stus[j+1].score) {
					Students temp = stus[j];
					stus[j] = stus[j+1];
					stus[j+1] = temp;
				}
			}
		}
	}
	
}
class Students{
	//学号
	int number;
	//班级
	int state;
	//分数
	int score;
	
	public void info() {
			System.out.println("学号:"+number+",班级："+state+"分数："+score);
	}
	
}

